package com.jucai.pppeiyouclient.adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;

import com.amap.api.maps2d.model.Text;
import com.jucai.pppeiyouclient.R;
import com.jucai.pppeiyouclient.base.CommonRecyclerViewAdapter;
import com.jucai.pppeiyouclient.bean.TransactionBean;

import java.util.List;

/**
 * Created by Kuky on 2017-04-18.
 */

public class TransactionAdapter extends CommonRecyclerViewAdapter<TransactionBean> {
    public TransactionAdapter(Context context, List<TransactionBean> data) {
        super(context, data);
    }

    @Override
    public void bindHolder(CommonHolder holder, TransactionBean transactionBean) {
        holder.setText(R.id.transaction_name, transactionBean.getCredit_log_content());
        holder.setText(R.id.transaction_time, transactionBean.getCredit_log_time());
        String num = "";
        if (!TextUtils.isEmpty(transactionBean.getCredit_log_num())){
            try{

                double d = Double.parseDouble(transactionBean.getCredit_log_num());
                if(d > 0){
                    num = "+"+d;
                }else{
                    num = transactionBean.getCredit_log_num();
                }
            }catch (Exception e){
                num = transactionBean.getCredit_log_num();
            }
        }else{
            num = transactionBean.getCredit_log_num();
        }

        if (TextUtils.equals(transactionBean.getCredit_log_change_way(),"0")) {
            holder.setText(R.id.transaction_record, /*"+" +*/ num + "元");
            //holder.setTextColor(R.id.transaction_record, Color.YELLOW);
        } else {
            holder.setText(R.id.transaction_record, num + "元");
            //holder.setTextColor(R.id.transaction_record, Color.RED);
        }
        holder.setTextColor(R.id.transaction_record, Color.WHITE);
    }

    @Override
    protected int getItemType(int position) {
        return 0;
    }

    @Override
    public int getLayoutId(int viewType) {
        return R.layout.item_transaction_layout;
    }
}
